package com.mt.roll.wms.controller;

import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.*;
import com.mt.roll.wms.service.AreaLocationService;
import com.mt.roll.wms.service.EquipmentAttrService;
import com.mt.roll.wms.service.EquipmentService;
import com.mt.roll.wms.vo.AreaLocationVo;
import com.mt.roll.wms.vo.EquipmentAttrVo;
import com.mt.roll.wms.vo.EquipmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @auther yanyang
 * @date 2021/11/01 10:56
 */

@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "equipment")
@Slf4j
@Api(value = "设备基础信息", tags = "设备基础信息", hidden = false)
public class EquipmentController extends BaseController {

    @Autowired
    private EquipmentService equipmentService;

    @PostMapping(value = "page")
    @ApiOperation(value = "设备基础信息")
    private R<PageVo<EquipmentVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody EquipmentQueryParam equipmentQueryParam) {
        return equipmentService.page(equipmentQueryParam);
    }

    @PostMapping(value = "get")
    @ApiOperation(value = "获取详情信息")
    private R<EquipmentVo> get(@Validated @RequestBody IdParam idParam) {
        return equipmentService.get(idParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增设备")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody EquipmentParam equipmentParam) {
        return equipmentService.add(equipmentParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody EquipmentParam equipmentParam) {
        return equipmentService.update(equipmentParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除设备信息")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return equipmentService.delete(idParam);
    }

    @PostMapping(value = "getCode")
    @ApiOperation(value = "获取code")
    private R<String> getCode() {
        return equipmentService.getCode();
    }



    @Autowired
    private EquipmentAttrService equipmentAttrService;

    @PostMapping(value="attr")
    @ApiOperation(value = "查看设备属性")
    private R<PageVo<EquipmentAttrVo>> attr(@Validated({PageGroup.class, Default.class}) @RequestBody EquipmentAttrQueryParam equipmentAttrQueryParam){
        return equipmentAttrService.attr(equipmentAttrQueryParam);
    }

    @PostMapping(value="attrById")
    @ApiOperation(value = "查看设备属性详情")
    private R<EquipmentAttrVo> attrById(@Validated @RequestBody IdParam idParam) {
        return equipmentAttrService.attrById(idParam);
    }

    @PostMapping(value="addattr")
    @ApiOperation(value = "添加属性")
    private R<IdVo> addAttr(@Validated({AddGroup.class, Default.class}) @RequestBody EquipmentAttrParam equipmentAttrParam) {
        return equipmentAttrService.addAttr(equipmentAttrParam);
    }

    @PostMapping(value = "updateattr")
    @ApiOperation(value = "更新属性")
    private R<IdVo> updateAttr(@Validated({UpdateGroup.class, Default.class}) @RequestBody EquipmentAttrParam equipmentAttrParam) {
        return equipmentAttrService.updateAttr(equipmentAttrParam);
    }

    @PostMapping(value = "deleteattr")
    @ApiOperation(value = "删除属性")
    private R<IdVo> deleteAttr(@Validated @RequestBody IdParam idParam) {
        return equipmentAttrService.deleteAttr(idParam);
    }

}

